# try:
#     可能发生异常的代码
# except 异常类型:
#     发生异常执行的代码
# else:
#     没有异常的时候执行的代码
# finally:
#     无论是否异常都要执行的代码

try:
    f = open("test.txt","r",encoding="utf8")
except:
    f = open("test.txt","w",encoding="utf8")
else:
    content = f.read()
    print(content)
finally:
    print("关闭资源")
    f.close()